package com.thoughtworks.tax;

import java.math.BigDecimal;

import com.thoughtworks.tax.strategy.SalesTaxStrategy;
import com.thoughtworks.tax.strategy.TaxStrategyFactory;

/**
 * represent the good
 * 
 * @author Tang Ling
 *
 */
public class Item
{
	private BigDecimal	account;
	private String		itemName;

	//used to output
	private Boolean		isImported;

	private BigDecimal	price;
	private ItemType	itemType;
	private BigDecimal	taxedAmount;
	private BigDecimal	shelfPrice;

	public static Item crteatItem(String price , ItemType type , String isImported , String itemName , int account)
	{
		Item i = new Item();
		i.setItemName(itemName);
		i.setPrice(new BigDecimal(price));
		i.setItemType(type);
		i.setIsImported(Boolean.valueOf(isImported));
		i.setAccount(new BigDecimal(account));

		//compute taxed amount
		SalesTaxStrategy strategy = TaxStrategyFactory.buildStrategy(i);
		i.setTaxedAmount(strategy.getSalesTax(i).multiply(i.getAccount()));
		i.setShelfPrice(i.getPrice().add(i.getTaxedAmount()));

		return i;
	}

	public Boolean getIsImported()
	{
		return isImported;
	}

	public void setIsImported(Boolean isImported)
	{
		this.isImported = isImported;
	}

	public BigDecimal getPrice()
	{
		return price;
	}

	public void setPrice(BigDecimal price)
	{
		this.price = price;
	}

	public ItemType getItemType()
	{
		return itemType;
	}

	public void setItemType(ItemType itemType)
	{
		this.itemType = itemType;
	}

	public BigDecimal getTaxedAmount()
	{
		return taxedAmount;
	}

	public void setTaxedAmount(BigDecimal taxedAmount)
	{
		this.taxedAmount = taxedAmount;
	}

	public BigDecimal getAccount()
	{
		return account;
	}

	public void setAccount(BigDecimal account)
	{
		this.account = account;
	}

	public String getItemName()
	{
		return itemName;
	}

	public void setItemName(String itemName)
	{
		this.itemName = itemName;
	}

	public BigDecimal getShelfPrice()
	{
		return shelfPrice;
	}

	public void setShelfPrice(BigDecimal shelfPrice)
	{
		this.shelfPrice = shelfPrice;
	}

	@Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder(this.account + " ");
		builder.append(isImported ? " imported " : "");
		builder.append(this.itemName);
		builder.append(" at ");
		builder.append(this.getShelfPrice());
		return builder.toString();
	}
}
